#!/bin/bash

#------------------------------------------------------------------------------
#Filename:      84417-lvm.sh
#Version:       1.0
#Date:          2014/06/25
#Author:        xi.zhang
#Email:         xi.zhang@cs2c.com.cn
#Summary:       02.02系统管理功能-02逻辑卷管理-02字符命令-19元数据的守护程序启动/停止/重启
#Notes:         元数据守护程序服务控制
#Copyright:     China Standard Software Co.,Ltd.
#History:
#               Version 1.0,2014/06/25
#               -The first one
#               Version 1.1,2014/10/22
#               -The second one
#               -Add SFROOT
#               -Rename variables 
#               -Add notes
#------------------------------------------------------------------------------

if [ -z "$SFROOT" ]
then
    CMDLIB=./
    SFROOT=./
else
    CMDLIB=${SFROOT}/testcases/Management_Function
fi

. ${SFROOT}/lib/Echo.sh
. ${SFROOT}/lib/UserOps.sh
. ${CMDLIB}/lib/Partition_parted.sh
. ${CMDLIB}/lib/PV.sh
. ${CMDLIB}/lib/VG.sh
. ${CMDLIB}/lib/LV.sh

IsRoot
EchoResult "脚本执行用户为root"

SERV=lvm2-lvmetad
CONF=`grep "use_lvmetad = 1" /etc/lvm/lvm.conf`
if [ -n "${CONF}" ];then
    EchoResult "Step 1 :Config File OK"
else
    mv /etc/lvm/lvm.conf /etc/lvm/lvm.conf.bak
    sed 's/use\_lvmetad\ \=\ 0/use\_lvmetad\ \=\ 1/' /etc/lvm/lvm.conf.bak > /etc/lvm/lvm.conf
    EchoResult "Step 1 :Modify Config File"
fi

command -v systemctl && /bin/systemctl start ${SERV}.service || /sbin/service ${SERV} start
EchoResult "Step 2 :Start the Service"

command -v systemctl && /bin/systemctl restart ${SERV}.service || /sbin/service ${SERV} restart
EchoResult "Step 3 :Restart the Service"

command -v systemctl && /bin/systemctl stop ${SERV}.service || /sbin/service ${SERV} stop
EchoResult "Step 4 :Stop the Service"
